package com.syn.synold4s.control;

import android.graphics.Rect;
import android.view.View;

import androidx.recyclerview.widget.RecyclerView;

public class RvFirstItemDecoration extends RecyclerView.ItemDecoration {
    private int margin;

    public RvFirstItemDecoration(int margin) {
        this.margin = margin;
    }

    @Override
    public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
        int position = parent.getChildAdapterPosition(view);
        if (position == 0) { // 第一行
            outRect.top = 0;
            outRect.left = margin;
            outRect.right = margin;
            outRect.bottom = 0;
        } else { // 其他行
            outRect.left = margin;
            outRect.right = margin;
            outRect.top = margin;
            outRect.bottom = 0;
        }
    }
}

